<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myStrategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/common.js"></script>
    <script src="../js/checkLogin.js"></script>
    <script>
        $(function () {
            var strategyId = getParams().id;
            var imgurls;//图片地址
            var tags = [];//标签数组
            var $uploadImg;//上传图片被几点的对象
            //绑定上传图片事件
            $(".imgs .rect").click(function () {
                $uploadImg = $(this);
                $("#file").click();
            })
            //读取图片上传事件来发送请求
            $("#file").change(function (data) {
                //如果有值就提交表单
                if ($(this).val()) {
                    $("#images").ajaxSubmit({
                        url: baseUrl + "images",
                        success: function (data) {
                            if (data.status) {
                                //回显上传的图片
                                $uploadImg.html("<img src='" + data.url + "' width='100%'/>");

                            }

                        }
                    })
                }

            });

            //绑定提交事件
            $("#submitBtn").click(function () {

                var imgs = $(".imgs img");//所有图片上传标签
                //遍历获取图片地址
                var temp = ''
                $.each(imgs, function (index, ele) {
                    if (ele) {
                        temp += $(ele).attr("src") + ";";
                    }
                });
                imgurls = temp;
                var json = {
                    dynamicsContent: $("textarea[name=content]").val(),
                    dynamicsPictrues: imgurls
                };
                $.post(baseUrl + "users/"+"friendDynamics", json, function (data) {
                    //保存成功跳回上一页时
                    if(data.success){
                        window.window.history.go(-1);
                    }
                })
            })

        })
    </script>
</head>
<body>

<div class="search-head">
    <div class="row nav-search">
        <div class="col-1">
            <a href="friendDynamics.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col-10">
            <span>发布我的动态</span>
        </div>
    </div>
</div>

<div class="comment">

    <div class="container tag">
        <p>添加动态内容</p>
        <textarea name="content" class="form-control" rows="5" placeholder="请填写您的分享"></textarea>

        <p>请为您的分享选择合适的标签</p>
        <div class="btn-group-toggle" data-toggle="buttons">
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="生活"> 生活
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="科技"> 科技
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="豪车"> 豪车
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="旅游景色">旅游景色
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="美女">美女
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="美食">美食
            </label>
        </div>

    </div>
    <!--更换封面的隐藏上传标签-->
    <form id="images" enctype="multipart/form-data" method="post">
        <input type="file" name="file" hidden id="file">
    </form>
    <div class="container imgs ">
        <p>上传图片</p>

        <div class="row">
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
        </div>
    </div>
</div>

<div class="operation">
    <button class="btn" onclick="window.history.go(-1)">放弃发布</button>
    <button class="btn" id="submitBtn">提交分享</button>
</div>


</body>


</html>